{include file="public_header" title="分红" /}
  <div class="main">
    <div class="notice"> 您当前的位置：<a href="{:url('common/index')}">首页</a> &gt; <a href="{:url('money/index')}" class="v-link-active">分红</a> </div>
    <div class="main_content">
      <div class="title"> <span>高级搜索</span> </div>
      <form class="layui-form">
        <div class="layui-inline mr10">
          <div class="layui-input-inline">
            <select name="plat_name" lay-verify="required" lay-search="">
              <option value="">所属平台</option>
              {volist name="plat_list_select" id="vo"}
                <option value="{$vo.id}" {if condition="$plat_id eq $vo.id"}selected{/if}>{$vo.plat_name}</option>
              {/volist}
            </select>
          </div>
        </div>
          <div class="layui-input-inline">
            <select name="belong" lay-verify="required" lay-search="">
              <option value="">所属销售</option>
              {volist name="sale" id="vo"}
                <option value="{$vo.id}" {if condition="$belong eq $vo.id"}selected{/if}>{$vo.realname}</option>
              {/volist}
            </select>
          </div>       
        <div class="layui-inline">
          <label class="layui-form-label">月份</label>
          <div class="layui-input-inline">
            <input type="text" name="months" class="layui-input" id="test16" placeholder="开始 到 结束" value="{$months}">
          </div>
        </div>    
        <button class="layui-btn" data-type="reload">搜索</button>         
      </form>
      <div class="title mt20"> <span>分红</span> </div>
	  {if condition="(in_array('Money/add',$user['account_auth'])) and ($user['position'] neq 1)"}
      <a class="btn mr10" id="add-money" href="javascript:;">添加</a>
	  {elseif condition="$user['position'] eq 1"/}
	  <a class="btn mr10" id="add-money" href="javascript:;">添加</a>
	  {/if}
	  {if condition="(in_array('Money/del',$user['account_auth'])) and ($user['position'] neq 1)"}
      <a class="btn do-action" href="javascript:;" data-type="doDelete" data-href="{:url('money/del')}">删除</a>	
	  {elseif condition="$user['position'] eq 1"/}
	  <a class="btn do-action" href="javascript:;" data-type="doDelete" data-href="{:url('money/del')}">删除</a>	
	  {/if}
      <div class="table">
         <table class="layuitable">
          <thead>
            <tr>
              <th width="50"><input type="checkbox" name=""></th>
              <th class="sort" width="80"><span>编号</span></th>
              <th class="sort" width="100"><span>平台名称</span></th>
              <th class="sort" width="100"><span>所属销售</span></th>
              <th class="sort" width="100"><span>提成比例</span></th>
              <th class="sort" width="100"><span>总分润金额</span></th>
              <th class="sort" width="100"><span>已下发代理分润金额</span></th>
              <th class="sort" width="100"><span>提成金额</span></th>
			  <th class="sort" width="100"><span>月份</span></th>
              <th width="80"><span>备注</span></th>
              <th width="150"><span>操作</span></th>
            </tr>
          </thead>
          <tbody>
            {volist name="money_list" id="vo"}
            <tr>
              <td><input type="checkbox" name="ck" ids="{$vo['id']}" value="true"></td>
              <td>{$vo.id}</td>
              <td>{$vo.plat_id}</td>
              <td>{$vo.belong}</td>
              <td>{$vo.bonus}%</td>
              <td>{$vo.total_money}</td>              
              <td>{$vo.down_money}</td>
              <td>{$vo.bonus_money}</td>
              <td>{$vo.months|date="Y-m",###}</td>
              <td>{$vo.remark}</td>
              <td>
				{if condition="(in_array('Money/edit',$user['account_auth'])) and ($user['position'] neq 1)"}
				<a class="blue goedit" href="javascript:;" data-id="{$vo.id}">修改</a>
				{elseif condition="$user['position'] eq 1"/}
				<a class="blue goedit" href="javascript:;" data-id="{$vo.id}">修改</a>
				{/if}
				{if condition="(in_array('Money/del',$user['account_auth'])) and ($user['position'] neq 1)"}
				<a class="blue do-action" id="del" href="javascript:;" data-type="doDelOne" data-href="{:url('money/del')}" data-id="{$vo['id']}">删除</a>
				{elseif condition="$user['position'] eq 1"/}
				<a class="blue do-action" id="del" href="javascript:;" data-type="doDelOne" data-href="{:url('money/del')}" data-id="{$vo['id']}">删除</a>
				{/if}
			  </td>
            </tr>
            {/volist}
          </tbody>
        </table>
      </div>
      <div class="page fr">
          <div class="page_fonts">共有{$count}条, 每页显示: 20条</div>
          <?php
            $fist_page = ($page == 1 ? 'no' : '1');
            $bottom_page = ($page == 1 ? 'no' : $page-1);
            echo("<a class=\"page_first\" href=\"javascript:gopage('".$fist_page."');\">&laquo;</a>");
            echo("<a class=\"page_prev\" href=\"javascript:gopage('".$bottom_page."');\">&lsaquo;</a>");
          ?>
          <div class="pages">
            <?php for($i = 1 ; $i <= ceil($count/20);$i++) {
              if($page == $i){
                echo("<a class=\"in\" href=\"javascript:gopage('no');\">$i</a>");
              }else{
                echo("<a href=\"javascript:gopage('".$i."');\">$i</a>");
              }
             } ?>
           </div>
           <?php
           $last_page = ($page == ceil($count/20) ? 'no' : ceil($count/20));
           $top_page = ($page == ceil($count/20) ? 'no' : $page+1);
           echo("<a class=\"page_first\" href=\"javascript:gopage('".$top_page."');\">&rsaquo;</a>");
           echo("<a class=\"page_prev\" href=\"javascript:gopage('".$last_page."');\">&raquo;</a>");
         ?>
        </div>
      <div class="clear"></div>      
    </div>
  </div>
</div>
<div id="set-add-money" style="display:none; width:550px; padding:20px;">
	<form class="layui-form" action="#" method="post" id="doAdd">
    <div class="layui-form-item">
      <label class="layui-form-label">平台名称</label>
      <div class="layui-input-inline">
        <select name="plat_id" lay-verify="required" lay-search="">
          <option value="">直接选择或搜索选择</option>
          {volist name="plat_list_select" id="vo"}
            <option value="{$vo.id}">{$vo.plat_name}</option>
          {/volist}
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">所属销售</label>
      <div class="layui-input-inline">
        <select name="belong" lay-verify="required" lay-search="">
          <option value="">直接选择或搜索选择</option>
          {volist name="sale" id="vo"}
          <option value="{$vo.id}">{$vo.realname}</option>
          {/volist}
        </select>
      </div>
    </div>	
    <div class="layui-form-item">
      <label class="layui-form-label">提成比例</label>
      <div class="layui-input-inline">
        <input type="text" name="bonus" lay-verify="required" autocomplete="off" placeholder="请输入提成比例" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">总分润金额</label>
      <div class="layui-input-inline">
        <input type="text" class="layui-input" name="total_money" placeholder="请输入总分润金额">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">已下发代理分润金额</label>
      <div class="layui-input-inline">
		<input type="text" class="layui-input" name="down_money" placeholder="请输入已下发代理分润金额">
      </div>
    </div>    
    <div class="layui-form-item">
      <label class="layui-form-label">提成金额</label>
      <div class="layui-input-inline">
        <input type="text" name="bonus_money" lay-verify="required" autocomplete="off" placeholder="请输入提成金额" class="layui-input">
      </div>
    </div> 
    <div class="layui-form-item">
      <label class="layui-form-label">月份</label>
      <div class="layui-input-inline">
		<input type="text" class="layui-input" id="test1" name="months" placeholder="yyyy-MM">      
      </div>
    </div> 	
    <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-inline">
		<textarea placeholder="请输入备注" name="remark" lay-verify="remark" class="layui-textarea"></textarea>
      </div>
    </div> 
    <div>	
	<button class="layui-btn layui-btn ml80" lay-submit lay-filter="form">提交</button>
    </div>
  </form>
</div>
<script>
//页面层
  $('#add-money').on('click', function(){
    layer.open({
      type: 1,
      area: ['550px', '520px'],
      shadeClose: true, //点击遮罩关闭
      content: $('#set-add-money')
    });
  });
  $('.goedit').on('click', function(){
	var id = $(this).data('id');
    layer.open({
      type: 2,
	  title: '编辑激活',
	  skin: 'layui-layer-rim', //加上边框
      area: ['800px', '520px'],
      content: '{:url('money/edit')}?id='+id+''
    });
  });    
layui.use('form', function(){
	var form = layui.form;
	var verify = function (obj) {
	    obj.addClass('layui-form-danger')
	        .focus()
	        .one('input',function () {
	            obj.removeClass('layui-form-danger').next('span').fadeOut();
	        })
	        .next('span').slideDown('fast');
	}
	form.on('submit(form)', function(data){
		$.ajax({
	        url:"{:url('money/add')}",
			    type:'POST',
	        data:$('#doAdd').serialize(),
	        dataType:"json",
	        error:function(data){
	            common.layerAlertE('链接错误！', '提示');
	        },
	        success:function(data){
	            if(data.code==1){
	                layer.msg(data.msg, {icon: 6,time:1000}, function(index){
	                    layer.close(index);
	                    window.location.href = "{:url('money/index')}";
	                });
	            }else{
	                layer.msg(data.msg, {icon: 5,time:2000});
	                return false;
	            }
	        }
	    });
	    return false;
	});
});
layui.use('laydate', function(){
  var laydate = layui.laydate;
  laydate.render({
    elem: '#test16'
    ,type: 'month'
    ,range: ','
  });  
  laydate.render({
    elem: '#test1'
    ,type: 'month'
  }); 
}); 
//分页
function gopage(page){
  if(page == "no"){
    alert('您已在这一页');
    return false;
  }
  window.location.href="{:url('money/index')}?plat_name={$plat_id}&belong={$belong}&months={$months}&page="+page;
}

//只显示相近的左右各五个分页按钮
$(function(){
  var page = "<?php echo($page);?>";
  if('<?php echo(ceil($count/20));?>' > 11){
    $('.pages>a').hide();
    $('.pages>a:eq('+(page-1)+')').show();
    for(var i = 1 ; i <= 5 ; i++){
      if(((page-1)-i) >= 0){
        $('.pages>a:eq('+((page-1)-i)+')').show();
      }
      if(((page-1)+i) <= '<?php echo(ceil($count/20));?>'){
        $('.pages>a:eq('+((page-1)+i)+')').show();
      }
    }
  }
});
</script>
</body>
</html>